package com.shop.config;

import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;
import com.shop.comment.Constants;
import com.shop.dao.base.DataSourceUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @Description TODO
 * @Author hyl
 * @Date 2022/3/15 9:26
 **/
public class SMSConfig {

	//生产环境请求地址：app.cloopen.com
	private static String serverIp ;
	//请求端口
	private static String serverPort;
	//主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
	private static String accountSId;
	private static String accountToken ;
	//请使用管理控制台中已创建应用的APPID
	private static String appId;

	static {
		init();
	}

	private static void init() {
		Properties params = new Properties();
		String configFile = Constants.Properties.SMS_PART;
		InputStream is = SMSConfig.class.getClassLoader().getResourceAsStream(configFile);
		try {
			params.load(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
		serverIp = params.getProperty("sms.serverIP");
		serverPort = params.getProperty("sms.serverPort");
		accountSId = params.getProperty("sms.accountSid");
		accountToken = params.getProperty("sms.authToken");
		appId = params.getProperty("sms.appID");
	}

	public static CCPRestSmsSDK getSmsSDK(){
		CCPRestSmsSDK sdk = new CCPRestSmsSDK();
		sdk.init(serverIp, serverPort,true);
		sdk.setAccount(accountSId, accountToken);
		sdk.setAppId(appId);
		sdk.setBodyType(BodyType.Type_XML);
		return sdk;
	}

}
